<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\ClockInDayRule;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class ClockInDayRuleController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new ClockInDayRule(), function (Grid $grid) {
            $grid->model() ->orderBy('sort','asc');

            $grid->column('id')->sortable();
            $grid->column('sort')->editable(true);
            $grid->column('integral');
            $grid->column('title');
            $grid->column('type')->display(function($type){
                return $type == 1 ? '每日规则'  : ($type == 2 ? '累计规则' : '');
            });
            $grid->column('day');

            $grid->disableCreateButton();
            $grid->disableDeleteButton();
            $grid->disableViewButton();
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new ClockInDayRule(), function (Show $show) {
            $show->field('id');
            $show->field('sort');
            $show->field('integral');
            $show->field('title');
            $show->field('type');
            $show->field('day');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new ClockInDayRule(), function (Form $form) {
            $form->display('id');
            $form->text('sort');
            $form->number('integral');
            $form->text('title');
            $form->text('type')->options([1=>'每日规则',2 => '累计规则']);
            $form->number('day');
        
            $form->display('created_at');
            $form->display('updated_at');

            $form ->disableViewButton();
            $form ->disableDeleteButton();
        });
    }
}
